<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="类型">
        <el-select v-model="queryParams.dateType" style="width: 100px;">
          <el-option label="日统计" value="day"></el-option>
          <el-option label="月统计" value="month"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="时间">
        <el-date-picker :editable="false" :clearable="false" style="width: 140px;"
                        v-model="queryParams.dayTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        v-show="queryParams.dateType==='day'"
                        placeholder="选择时间">
        </el-date-picker>
        <el-date-picker :editable="false" :clearable="false" style="width: 140px;"
                        v-model="queryParams.monthTime"
                        type="month"
                        value-format="yyyy-MM"
                        v-show="queryParams.dateType==='month'"
                        placeholder="选择时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="reportTj">统计</el-button>
      </el-form-item>
    </el-form>
    <div style="margin-bottom: 10px;margin-left: 10px;">
      <span v-if="queryParams.dateType==='day'" style="color:#707070;">注：日统计 单位(分钟)</span>
      <span v-else style="color:#707070;">注：月统计 单位(小时)</span>
    </div>
    <el-table v-loading="loading" :stripe="true" :data="reportList" :max-height="tabHt">
      <el-table-column width="180" fixed :label="`监测站点`" align="center" prop="pointName" />
      <el-table-column v-for="obj in headObj" :label="obj.title" :key="obj.key" align="center">
        <el-table-column width="70" :label="`在线`" align="center" :prop="`${obj.key}zx`" >

          <template v-slot="scope" v-if="queryParams.dateType==='day'">
            <span v-if="scope.row[`${obj.key}zx`]" >{{scope.row[`${obj.key}zx`]*10}}</span>
            <span v-else >0</span>
          </template>
          <template v-slot="scope" v-else>
            <span v-if="scope.row[`${obj.key}zx`]" >{{(scope.row[`${obj.key}zx`]*10/60).toFixed(1)}}</span>
            <span v-else >0</span>
          </template>

        </el-table-column>
        <el-table-column width="70" :label="`离线`" align="center" :prop="`${obj.key}lx`" >

          <template v-slot="scope" v-if="queryParams.dateType==='day'">
            <span v-if="scope.row[`${obj.key}zx`]" >{{(6-scope.row[`${obj.key}zx`])*10}}</span>
            <span v-else >60</span>
          </template>
          <template v-slot="scope" v-else>
            <span v-if="scope.row[`${obj.key}zx`]" >{{((144-scope.row[`${obj.key}zx`])*10/60).toFixed(1)}}</span>
            <span v-else >{{1440/60}}</span>
          </template>

        </el-table-column>
        <el-table-column width="70" :label="`在线率`" align="center" :prop="`${obj.key}zxl`" >

          <template v-slot="scope" v-if="queryParams.dateType==='day'">
            <span v-if="scope.row[`${obj.key}zx`]" style="color:#00ff00;">{{((scope.row[`${obj.key}zx`]*10)/60).toFixed(2)*100}}%</span>
            <span v-else >
              {{0}}%
            </span>
          </template>
          <template v-slot="scope" v-else>
            <span v-if="scope.row[`${obj.key}zx`]" style="color:#00ff00;">{{((scope.row[`${obj.key}zx`]*10)/60/24).toFixed(2)*100}}%</span>
            <span v-else >
              {{0}}%
            </span>
          </template>

        </el-table-column>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
  import { listPointNetworkRecord } from "@/api/basic/pointNetworkRecord";

export default {
  name: "SticsOnline",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      headObj:[{'title':'11月01日01时','key':'key110101'},{'title':'11月01日02时','key':'key110102'}],
      reportList:[{'pointName':'福州站','key110101zx':'31','key110101lx':'29'},{'pointName':'厦门站','key110101zx':'21','key110101lx':'39'}],
      // 日期范围
      dateRange: "",
      // 查询参数
      queryParams: {
        dateType:'day',
        dayTime:null,
        monthTime:null,
      },
    };
  },
  computed: {
    tabHt(){
      return this.$store.state.app.tableHeight.htp
    }
  },
  mounted() {
    let nowDate = new Date();
    let byear = nowDate.getFullYear();
    let bmonth = nowDate.getMonth() + 1;
    let bday = nowDate.getDate();
    this.queryParams.dayTime = `${byear}-${bmonth}-${bday}`;
    this.queryParams.monthTime = `${byear}-${bmonth}`;
  },
  created() {
    this.$nextTick(() => {
      this.reportTj();
    });

  },
  methods: {
    /** 查询监测站点联网记录列表 */
    reportTj() {
      this.loading = true;
      listPointNetworkRecord(this.queryParams).then(response => {
        this.headObj = response.data.headObj;
        this.reportList = response.data.reportList;
        this.loading = false;
      });
    },
  }
};
</script>
